<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style>@media print {
        #ghostery-purple-box {
            display: none !important
        }
    }</style>
    <style type="text/css">
        body {
            background-color: #7c7c7c;
            margin-left: 0px;
            margin-top: 0px;
        }

        .video-js.vjs-center {
            width: 100%;
            height: 45vw;
            display: table;
            margin: 0 auto;
        }

        /*body {
            background-color: rgb(23, 23, 23);
            color: #ffffff;
        }*/

        .lucklist .button {
            width: 60%;
        }

        .ui.grid > .column:not(.row) {
            padding-top: 0.5rem;
            padding-bottom: 0.5rem;
        }

        .four.wide.mobile.two.wide.computer.column {
            padding-left: 0.2em;
            padding-right: 0.2em;
        }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>设置端口</title>
    <meta name="referrer" content="never">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>* {
        margin: 0;
        padding: 0
    }</style>
    <link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://unpkg.com/video.js/dist/video.js"></script>
    <link href="./src/semantic.min.css" rel="stylesheet">
    <script src="./src/semantic.min.js"></script>
</head>
<body>
<script>
    var juHuiCache = {};
    var juHuiCacheFile = "hiker://files/JuHuiCache.json";

    function getCache() {
        try {
            let data = request(juHuiCacheFile);
            if (data != null && data.length > 0) {
                juHuiCache = JSON.parse(data);
            } else {
                throw e.toString();
            }
        } catch (e) {
            fy_bridge_app.writeFile(juHuiCacheFile, '');
            throw e.toString();
        }
    }

    function saveCache() {
        let saveSuccess = false;
        try {
            fy_bridge_app.writeFile(juHuiCacheFile, JSON.stringify(juHuiCache));
            saveSuccess = true;
        } catch (e) {
            console.log(e);
        }
        return saveSuccess;
    }

    function getLuckNumberFromCache() {
        try {
            if (juHuiCache.lucknum == null || juHuiCache.lucknum === "") {
                getCache();
            }
        } catch (e) {
            console.log(e);
            juHuiCache.lucknum = "69";
        }
        return juHuiCache.lucknum;
    }

    function initLuckNumber(luckNumber) {
        $(".lucknumbernow").html(luckNumber.toString());
    }

    function updateLuckNumber(luckNumber) {
        juHuiCache.lucknum = luckNumber;
        if (saveCache() === true) {
            $(".lucknumbernow").html(luckNumber.toString());
        } else {
            $(".lucknumbernow").html("保存失败");
        }
        return luckNumber;
    }

    function getHash() {
        var hash = "SnWbEff2sTDiBZXQJ1GvqEeRBDoWYwE43yg1w77qSRNZDo5pr";
        var currentUrl = window.location.href;
        var hashFromUrl = currentUrl.split("#")[1];
        if (hashFromUrl != null && hashFromUrl !== "") {
            hash = hashFromUrl;
        }
        return hash;
    }

    var luckNumber = getLuckNumberFromCache();
    var hash = getHash();
    var videoUrl = "https://ipfs" + luckNumber + ".365kqzs.cn:9081/ipfs/" + hash;

    var isWap = navigator.userAgent.match(/iPad|iPhone|iPod|Android/i) != null;
    var vid = (videoUrl);
    // width="100%" height="100%"
    if (isWap) {
        document.writeln('<video id="my_video_1" class="video-js vjs-big-play-centered vjs-center" src="' + vid + '" controls="controls" preload="preload" poster="https://wx1.sinaimg.cn/mw690/005yF2tCgy1fn67stcy3wg30jq0dwq2z.gif"></video>');
    } else {
        document.writeln('<video id="my_video_1" class="video-js vjs-big-play-centered vjs-fill"  controls preload="auto" data-setup=\'{}\' >\n' +
            '    <source src="' + (videoUrl) + '" type="video/mp4"></source>\n' +
            '</video>');
    }
</script>
<div class="ui textselect">
    <div class="header centered" style="text-align: center; margin-top: 10px; margin-bottom: 10px;">
        <h3>试试运气</h3>
        <p>当前：<span class="lucknumbernow" style="color: #db9540">暂无</span></p>
    </div>
    <div class="ui divider"></div>
    <div class="centered" style="text-align: center; margin-top: 10px; margin-bottom: 10px;">
        <h4 id="cw" style="color: black;"></h4>
        <div class="ui action labeled input">
            <div class="ui label">https://ipfs</div>
            <input class="lucknumber" type="text" placeholder="数字">
            <button class="ui icon button luck">
                <i class="arrow right icon"></i>
            </button>
        </div>
        <h5 id="tips_save" style="color: #a3a3a8;"></h5>
        <div class="ui divider"></div>
        <div class="ui grid lucklist">
        </div>
    </div>
    <!--    <div class="actions">-->
    <!--        <div class="ui negative button">关闭</div>-->
    <!--        <div class="ui positive right labeled icon button luck">确认<i class="checkmark icon"></i>-->
    <!--        </div>-->
    <!--    </div>-->
</div>
</body>
</html>
<script type="text/javascript">
    $(function () {
        $(".luck").on("click", function () {
            let url = "https://ipfs" + $(".lucknumber").val() + ".365kqzs.cn:9081/ipfs/" +
                hash;
            // fy_bridge_app.playVideo(url);
            console.log(url);
            changeVideo($(".lucknumber").val())
        })
    });
    window.onload = function () {
        /*var videoPanelMenu = $(".vjs-fullscreen-control");
        videoPanelMenu.before('<div class="vjs-subs-caps-button  vjs-menu-button vjs-menu-button-popup vjs-control vjs-button"  aria-live="polite" aria-expanded="false" aria-haspopup="true">'
            + '<div class="vjs-menu" role="presentation">'
            + '<ul class="vjs-menu-content" role="menu">'
            + '<li class="vjs-menu-item" tabindex="-1" role="menuitemcheckbox"  onclick="changeVideo(1)">普通</li>'
            + '<li class="vjs-menu-item" tabindex="-1" role="menuitemcheckbox"  onclick="changeVideo(2)">标清 </li>'
            + '<li class="vjs-menu-item" tabindex="-1" role="menuitemcheckbox"  onclick="changeVideo(3)">高清 </li>'
            + '</ul></div>'
            + '  <button class="vjs-subs-caps-button vjs-control vjs-button" type="button" aria-live="polite" title="清晰度切换" aria-disabled="false">'
            + '      <span aria-hidden="true" class="vjs-icon-placeholder"></span><span class="vjs-control-text">清晰度切换</span>'
            + '  </button>'
            + '</div>'
        );*/
        initLuckNumber(luckNumber);
        var obj = {tag: false, ctime: 0};
        window.obj = obj;
        var myPlayer = videojs.getPlayers()['my_video_1'];
        myPlayer.on("timeupdate", function () {
            if (window.obj.tag) {
                videojs("my_video_1").currentTime(window.obj.ctime);
                videojs("my_video_1").play();
                window.obj.tag = false;
            }
            //视频打点
            var ctime_ = videojs("my_video_1").currentTime().currentTime();
            if (ctime_ == 60) {
                videojs("my_video_1").currentTime(ctime_ + 1);
                //do something
            }
        });
    };

    function changeVideo(luckNumber) {
        let url = 'https://ipfs'
            + luckNumber
            + '.365kqzs.cn:9081/ipfs/' + hash;
        let ctime = videojs("my_video_1").currentTime();
        videojs("my_video_1").src([{
            type: "video/mp4",
            src: (url)
        }]);
        videojs("my_video_1").play();
        window.obj.ctime = ctime;
        window.obj.tag = true;
        updateLuckNumber(luckNumber);
    }

    // $(".modal").modal("show");
    $(".lucklist").html("");
    $("#cw").html('尽管“' + '找不到可用地址' + '”<br/>但是你可以试试输入数字或者点击下面的按钮，顺序按照访问速度排列。');
    $("#tips_save").html("访问成功后会自动保存选择的接口，返回刷新二级列表即可~");
    for (let i = 1; i < 30; i++) {
        var xhr = $.ajax({
            type: 'HEAD',
            url: 'https://ipfs' + i +
                '.365kqzs.cn:9081/ipfs/' + hash,
            timeout: 5000,
            complete: function (xhr, data) {
                if (xhr.readyState == 4 && xhr.status == 200)
                    $(".lucklist").append(
                        '<div class="four wide mobile two wide computer column"><button onclick="changeVideo(\'' + i + '\');" class="ui button">' +
                        i + '</button></div>'
                    );
            }
        });
    }
</script>
